// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... namespace LargoBase.Motives { using LargoBase.Abstract; using LargoBase.Enums; using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using System.Xml.Linq; /// /// Rhythmic Change. /// public sealed class RhythmicChange : AbstractChange { #region Fields /// Rhythmic motive. private RhythmicMotive rhythmicMotive; #endregion #region Constructors /// /// Initializes a new instance of the class. /// [UsedImplicitly] public RhythmicChange() { } /// /// Initializes a new instance of the class. /// /// The given change. public RhythmicChange(XElement xchange) : base(xchange) { Contract.Requires(xchange != null); //// if (xchange == null) { return; } this.MotiveNumber = XmlSupport.ReadIntegerAttribute(xchange.Attribute("MotiveNumber")); this.MotivicChange = (MotivicChangeType)XmlSupport.ReadByteAttribute(xchange.Attribute("MotivicChange")); this.MusicalLineType = MusicalLineType.Rhythmic; this.ChangeType = MusicalChangeType.Rhythmic; } /// /// Initializes a new instance of the class. /// /// The given bar. /// The given line. public RhythmicChange(int givenBar, int givenLine) : base(givenBar, givenLine, MusicalChangeType.Rhythmic) { this.MusicalLineType = MusicalLineType.Rhythmic; } #endregion #region Properties - Xml /// /// Gets Xml representation. /// /// /// Property description. /// public override XElement GetXElement { get { var change = base.GetXElement; change.Add(new XAttribute("MotiveNumber", this.MotiveNumber ?? 0)); change.Add(new XAttribute("MotivicChange", (byte)this.MotivicChange)); return change; } } #endregion #region Properties /// Gets or sets class of melodic part. /// Property description. public int? MotiveNumber { get; set; } /// /// Gets or sets the line letter. /// /// /// The line letter. /// public int? LineLetter { get; set; } /// /// Gets or sets the motivic change. /// /// /// The motivic change. /// public MotivicChangeType MotivicChange { get; set; } /// /// Gets or sets TRhythmicMotive. /// /// General musical property. public RhythmicMotive RhythmicMotive { get { if (this.MotiveNumber == null) { return null; } var isPrepared = this.rhythmicMotive != null; if (isPrepared) { return this.rhythmicMotive; } ////core bool isPrepared = (this.rhythmicMotive != null) && this.rhythmicMotive.Number == this.MotiveNumber ////core && this.rhythmicMotive.CoreId == this.BlockModel.RhythmicCore.Id; ////core if (isPrepared) { return this.rhythmicMotive; } //// if (this.HasModel) { //// this.rhythmicMotive = this.BlockModel.Core.RhythmicCore.GetRhythmicMotive((int)this.MotiveNumber); //// } return this.rhythmicMotive; } set => this.rhythmicMotive = value; } #endregion #region Static factory methods /// /// Gets the new end rhythmic change. /// /// The bar number. /// The line number. /// Returns object. public static RhythmicChange GetNewRhythmicStopChange(int barNumber, byte lineIndex) { Contract.Ensures(Contract.Result() != null); var change = new RhythmicChange(barNumber, lineIndex) { MotivicChange = MotivicChangeType.MainMotiveStop }; return change; } #endregion #region Public methods /// /// Clones this instance. /// /// Returns object. public override object Clone() { var tmc = new RhythmicChange(this.BarNumber, this.LineIndex) { MotiveNumber = this.MotiveNumber, MotivicChange = this.MotivicChange }; //// tmc.BlockModel = this.BlockModel; return tmc; } #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.AppendFormat(CultureInfo.CurrentCulture, base.ToString()); s.Append(", Motive " + this.MotiveNumber); return s.ToString(); } #endregion } }